#ifndef LISTFORM_H
#define LISTFORM_H

#include "csballfm.h"

typedef enum {usOffline, usOnline} UserStatus;
struct UserInfo
{
    QString uin;
    QString nick;
    UserStatus status;
    bool ballActive; // user have its own ball:)

    UserInfo() :
        nick("ktoto"),
        status(usOffline),
        ballActive(false)
        {uin = QString::number(rand());}
};

class SListForm : public SCustomBallForm
{
    Q_OBJECT

private:
    bool pMinimized;
    QString pTitle;
    int maxRadius;
    QImage listImage, tempImage;

    QList<UserInfo> userList;
    QMap<QString, UserInfo*> userMap;
    int scrollPos, targetScrollPos;
    int maxHeight;
    int itemHeight;
    int curIdx;
    int curDrawY;

    QTimer timer;
    QMovie *closingMovie;

protected:
    void mousePressEvent(QMouseEvent *mouse);
    void mouseDoubleClickEvent(QMouseEvent *e);
    void wheelEvent(QWheelEvent *wheel);

    void paint();
    void paintList();

    void sortList();

public:
    explicit SListForm(QWidget *parent = 0);

    void add(UserInfo *info);
    void add(QString nick);
    void clear();
    //void change(QString uin, UserInfo *info);
    UserInfo* userInfo(QString uin) {return userMap.contains(uin)? userMap[uin]: 0L;}

    void setUserStatus(QString uin, UserStatus status);

signals:
    void userSelected(QString uin, bool active);
    
private slots:
    void onTimer();
    void onClosed();
    void paintMovieFrame();

protected slots:
    void PaintBack(QImage *img);

public slots:
    void setUserActive(QString uin, bool active);
    void setMinimized(bool minimized);
    void close();
};

#endif // SLISTFORM_H
